<template>
	<div id="container">
		<div id="center">
			<el-form label-width="120px" label-position='right' :rules="formRules" :model="departureInfo" status-icon>
				<el-form-item label="员工编号:" prop="staff_no">
					<el-input disabled v-model="departureInfo.staff_no"></el-input>
				</el-form-item>
				<el-form-item label="员工姓名:" prop="staff_name">
					<el-input disabled v-model="departureInfo.staff_name"></el-input>
				</el-form-item>

				<el-form-item label="离职时间" prop="staff_departure_time">
					<el-date-picker v-model="departureInfo.staff_departure_time" value-format="YYYY-MM-DD" type="date"
						placeholder="离职时间" style="width: 100%" />
				</el-form-item>

				<el-form-item label="离职类型:" prop="staff_departure_type">
					<el-select v-model="departureInfo.staff_departure_type">
						<el-option label="主动辞职" value="主动辞职"></el-option>
						<el-option label="辞退" value="辞退"></el-option>
						<el-option label="退休" value="退休"></el-option>
						<el-option label="开除" value="开除"></el-option>
						<el-option label="试用期未通过" value="试用期未通过"></el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="离职去向:">
					<el-input v-model="departureInfo.staff_departure_leave_to"></el-input>
				</el-form-item>

				<el-form-item label="进入人才库?" prop="staff_if_enter_talent_pool">
					<el-select v-model="departureInfo.staff_if_enter_talent_pool">
						<el-option label="是" value="1"></el-option>
						<el-option label="否" value="0"></el-option>
					</el-select>
				</el-form-item>

				<el-form-item label="备注:">
					<el-input v-model="departureInfo.notes"></el-input>
				</el-form-item>

				<el-form-item>
					<el-button size="large" type="primary" @click="handleUpdate()" style="width: 100%;">修改</el-button>
				</el-form-item>
			</el-form>
		</div>
		<!-- <div id="bottom">
			版权归东软教育所有
		</div> -->
	</div>
</template>

<script>
	export default {
		name: 'DepartureInfoUpdateView',
		data() {
			return {
				departureInfo: {
					p_name: '',
					staff_name: '',
					staff_no: '',
					staff_sex: '',
					staff_phone: '',
					staff_status: '',
					staff_department: '',
					staff_departure_time: '',
					staff_departure_type: '',
					staff_departure_leave_to: '',
					staff_if_enter_talent_pool: '',
					notes: '',
				},
				departureInfos: [],
				formRules: {
					staff_departure_time: [{
						type: 'date',
						required: true,
						message: '请选择时间',
						trigger: 'blur',
					}],
					staff_departure_type: [{
						required: true,
						message: '请选择离职类型',
						trigger: 'blur',
					}],
					staff_if_enter_talent_pool: [{
						required: true,
						message: '请确认是否进入人才库',
						trigger: 'blur',
					}],
				}
			}
		},
		created() {
			let str = sessionStorage.getItem("departureInfo");
			if (str == null || str == '') {
				this.$router.push("/DepartureInfoSearch");
			} else {
				this.departureInfo = JSON.parse(str);
				console.log(this.departureInfo);
			}
		},
		methods: {
			handleUpdate() {
				//获取页面中控件的值
				let str = JSON.stringify(this.departureInfo);
				console.log(str)

				if (this.departureInfo.staff_departure_time != null && this.departureInfo.staff_departure_type != null &&
					this.departureInfo.staff_if_enter_talent_pool !=
					null) {
					if (this.departureInfo.staff_departure_time != "" && this.departureInfo.staff_departure_type != "" &&
						this.departureInfo.staff_if_enter_talent_pool !=
						"") {
						this.$axios.post("http://localhost:8088/eStaff/StaffDepartureInfo/infoUpdate", this.departureInfo)
							.then(rst => {
								if (rst.data.code == 200) {
									// this.$message("操作结束");
									this.$alert(rst.data.msg, "成功");
									console.log(rst.data);
								} else {
									this.$alert(rst.data.msg, "失败");
								}

							}).catch(err => {
								console.log(err);
							})
						this.$router.push("/DepartureInfoSearch");
					}
				}
			}
		}
	}
</script>

<style scoped>
	#container {
		width: 100%;
		height: 100%;
		/* 弹性布局 */
		display: flex;
		/* 伸缩方向：列方向 */
		flex-direction: column;
		/* background-image: url("../../assets/image03.jpg"); */
		/* background-color: aliceblue; */
	}

	#top {
		width: 100%;
		height: 80px;
		border-bottom: 1px solid darkgray;
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 0px 20px;
		box-sizing: border-box;
	}

	#top #logo {
		font-size: 50px;
		font-family: 楷体;
		text-shadow: 5px 5px 5px gray;
		font-style: italic;
		font-weight: bolder;
	}

	#top #info {
		font-size: 12px;
	}

	#top a {
		text-decoration: none;
	}

	#center {
		width: auto;
		flex: 1;
		/*占父容器剩下容量的一份*/
		display: flex;
		padding: 20px;
		box-sizing: border-box;
		justify-content: center;
	}

	#bottom {
		width: 100%;
		height: 30px;
		font-size: 12px;
		border-top: 1px solid darkgray;
		display: flex;
		justify-content: center;
		align-items: center;
	}
</style>
